package com.qt.judge;

import java.util.List;

/**
 * @author pgw
 * @version 1.0
 * @description
 * @date Create by 2023/10/12 16:27
 */
public class JudgeHolder {

    public static final String COMPILE_SCRIPT_NAME = "compile.sh";
    public static final String JUDGE_CORE_SCRIPT_NAME = "y_judge";
    public static final String COMPARE_SCRIPT_NAME = "compare.sh";
    public static final String CODE_FILE_NAME = "Main";
    public static final String COMPILE_STD_OUT_NAME = "compile.out";
    public static final String COMPILE_STD_ERR_NAME = "compile.err";
    public static final String RUNNER_SCRIPT_NAME = "run";

    private static final ThreadLocal<JudgeConfiguration> JUDGE_HOLDER_THREAD_LOCAL = new ThreadLocal<>();

    public static JudgeConfiguration getJudgeConfiguration() {
        return JUDGE_HOLDER_THREAD_LOCAL.get();
    }

    public static void removeThreadLocal() {
        JUDGE_HOLDER_THREAD_LOCAL.remove();
    }
    public static void initJudgeConfiguration(JudgeConfiguration judgeConfiguration) {
        JUDGE_HOLDER_THREAD_LOCAL.set(judgeConfiguration);
    }

    public static Runtime getRunner() {
        return getJudgeConfiguration().getRunner();
    }

    public static String getCompileScriptPath() {
        return getJudgeConfiguration().getScriptPath() + "/" + COMPILE_SCRIPT_NAME;
    }

    public static String getJudgeWorkingPath() {
        return getJudgeConfiguration().getSubmitssionPath() + "/" + getSubmissionId();
    }

    public static Long  getSubmissionId() {
        return getJudgeConfiguration().getJudgeId();
    }

    public static String getJudgeCoreScriptPath() {
        return getJudgeConfiguration().getScriptPath() + "/" + JUDGE_CORE_SCRIPT_NAME;
    }


    public static String getSubmissionPath() {
        return getJudgeConfiguration().getSubmitssionPath() + "/" + getSubmissionId();
    }

    public static String getCodePath(String extension) {
        return getSubmissionPath() + "/" + CODE_FILE_NAME + "." + extension;
    }
    public static String getRunnerScriptPath() {
        return getSubmissionPath() + "/" + RUNNER_SCRIPT_NAME;
    }

    public static String getCompareScriptPath() {
        return getJudgeConfiguration().getScriptPath() + "/" + COMPARE_SCRIPT_NAME;
    }
}
